<template>
  <div>
    <el-form
      :model="ruleForm"
      status-icon
      :rules="rules"
      ref="ruleForm"
      label-position="left"
      label-width="0px"
      class="login-container"
      @keyup.enter.native="submitForm('ruleForm')"
    >
      <h3 class="login_title">酒店后台登录系统</h3>
      <el-form-item prop="pass">
        <el-input
          placeholder="请输入管理员账号"
          type="text"
          v-model="ruleForm.user"
          autocomplete="off"
        ></el-input>
      </el-form-item>
      <el-form-item prop="checkPass">
        <el-input
          placeholder="请输入管理员密码"
          type="password"
          v-model="ruleForm.checkPass"
          autocomplete="off"
        ></el-input>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          @click="submitForm('ruleForm')"
          class="logining"
          >提交</el-button
        >
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  data() {
    var Adminuser = (rule, value, callback) => {
      if (this.ruleForm.user === "") {
        callback(new Error("请输入账号"));
      } else if (this.ruleForm.user !== "admin") {
        callback(new Error("输入账号错误,请重新输入!"));
      } else {
        callback();
      }
    };
    var Adminpwd = (rule, value, callback) => {
      if (value === "") {
        callback(new Error("请输入密码"));
      } else if (value !== "admin") {
        callback(new Error("输入密码错误,请重新输入!"));
      } else {
        callback();
      }
    };
    return {
      ruleForm: {
        user: "",
        checkPass: "",
      },
      rules: {
        pass: [{ validator: Adminuser, trigger: "blur" }],
        checkPass: [{ validator: Adminpwd, trigger: "blur" }],
      },
    };
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          localStorage.setItem("loginStatus", "1");
          this.$router.push("/myadmin");
        } else {
          console.log("错误 请重新输入!!");
          return false;
        }
      });
    },
  },
};
</script>

<style>
body {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
}
.login_title {
  margin: 0 auto 20px auto;
  color: #505458;
  font-size: 25px;
  font-weight: bold;
}

.login-container {
  position: absolute;
  top: 50%;
  right: 50%;
  transform: translate(50%, -50%);
  width: 350px;
  background: #fff;
  border-radius: 15px;
  background-clip: padding-box;
  box-shadow: 0px 0px 25px #cac6c6;
  margin: auto;
  padding: 35px;
}

.logining {
  width: 100%;
}
</style>
